﻿<%@ Page Title="" Language="C#" MasterPageFile="~/CricketAdmin.master" AutoEventWireup="true"
    CodeFile="AdminFancy.aspx.cs" Inherits="AdminFancy" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
    <script language="javascript" src="js/jquery-1.10.1.min.js" type="text/javascript"></script>
    <script type="text/javascript" language="javascript">

        $(document).ready(function () {

            $("#btnTeamAStart").hide();
            $("#btnTeamBStart").hide();
            $("#btnTeamAEnd").hide();
            $("#btnTeamBEnd").hide();


            $('#<%=txtTeamAOver.ClientID %>').hide();
            $('#<%=txtTeamARate.ClientID %>').hide();

            $('#<%=txtTeamBOver.ClientID %>').hide();
            $('#<%=txtTeamBRate.ClientID %>').hide();


            if ($('#<%=drpMatch.ClientID %> option:selected').text() != "Select Match" && $('#<%=drpMatch.ClientID %> option:selected').text() != "") {

                HideBettingTeamB();
                $("#btnTeamABettingStart").show();
                $("#btnTeamBBettingStart").show();

            }






            $('#<%=txtTeamARate.ClientID %>').keypress(function (event) {
                return isNumber(event)
            });

            $('#<%=txtTeamBRate.ClientID %>').keypress(function (event) {
                return isNumber(event)
            });





            $('#<%=txtTeamAOver.ClientID %>').keyup(function () {
                var textboxValue = $('#<%=txtTeamAOver.ClientID %>').val();
                if ($('#<%=drpMatchType.ClientID %> option:selected').text() == "One Day") {
                    if (textboxValue.length == 2) {
                        $('#<%=txtTeamARate.ClientID %>').focus();
                    }
                }
                else if ($('#<%=drpMatchType.ClientID %> option:selected').text() == "Test") {
                    if (textboxValue.length == 3) {
                        $('#<%=txtTeamARate.ClientID %>').focus();
                    }
                }
                else if ($('#<%=drpMatchType.ClientID %> option:selected').text() == "T20") {
                    if (textboxValue.length == 2) {
                        $('#<%=txtTeamARate.ClientID %>').focus();
                    }
                }
            });

            $('#<%=txtTeamBOver.ClientID %>').keyup(function () {
                var textboxValue = $('#<%=txtTeamBOver.ClientID %>').val();
                if ($('#<%=drpMatchType.ClientID %> option:selected').text() == "One Day") {
                    if (textboxValue.length == 2) {
                        $('#<%=txtTeamBRate.ClientID %>').focus();
                    }
                }
                else if ($('#<%=drpMatchType.ClientID %> option:selected').text() == "Test") {
                    if (textboxValue.length == 3) {
                        $('#<%=txtTeamBRate.ClientID %>').focus();
                    }
                }
                else if ($('#<%=drpMatchType.ClientID %> option:selected').text() == "T20") {
                    if (textboxValue.length == 2) {
                        $('#<%=txtTeamBRate.ClientID %>').focus();
                    }
                }

            });

        });


        function isNumber(evt) {
            var charCode = (evt.which) ? evt.which : event.keyCode
            if (charCode != 45 && (charCode != 46 || $(this).val().indexOf('.') != -1) &&
                (charCode < 48 || charCode > 57))
                return false;

            return true;
        }

        function StartBettingTeamA() {
            $('#<%=txtTeamARate.ClientID %>').show();
            if ($('#<%=drpBettingType.ClientID %> option:selected').text() == "90/110") {
                HideBettingTeamB();
                $("#btnTeamABettingStart").hide();
                $("#btnTeamBBettingStart").hide();
                $('#<%=txtTeamAOver.ClientID %>').show();
                $('#<%=txtTeamAOver.ClientID %>').focus();
            }
            $("#btnTeamAStart").show();
        }

        function StartBettingTeamB() {
            $('#<%=txtTeamBRate.ClientID %>').show();
            if ($('#<%=drpBettingType.ClientID %> option:selected').text() == "90/110") {
                HideBettingTeamA();
                $("#btnTeamABettingStart").hide();
                $("#btnTeamBBettingStart").hide();
                $('#<%=txtTeamBOver.ClientID %>').show();
                $('#<%=txtTeamBOver.ClientID %>').focus();
            }
            $("#btnTeamBStart").show();
        }
        function HideBettingTeamA() {
            $("#btnTeamBBettingStart").show();
            $("#btnTeamABettingStart").hide();
            $('#<%=txtTeamARate.ClientID %>').hide();
            $('#<%=txtTeamAOver.ClientID %>').hide();
            $("#btnTeamAStart").hide();
            $("#btnTeamAEnd").hide();
        }
        function HideBettingTeamB() {
            $("#btnTeamABettingStart").show();
            $("#btnTeamBBettingStart").hide();
            $('#<%=txtTeamBRate.ClientID %>').hide();
            $('#<%=txtTeamBOver.ClientID %>').hide();
            $("#btnTeamBStart").hide();
            $("#btnTeamBEnd").hide();
        }



        function SaveBetting(whichTeam) {

            var bettingTypeId = $('#<%=drpBettingType.ClientID %>').val();
            var matchTypeId = $('#<%=drpMatchType.ClientID %>').val();
            var matchScheduleId = $('#<%=drpMatch.ClientID %>').val();
            var teamId = 0;
            var lagadiRate = 0;
            var over = 0;


            if ($('#<%=drpBettingType.ClientID %> option:selected').text() == "90/110") {
                if (whichTeam == 'teamA') {
                    $("#btnTeamBBettingStart").hide();
                    if (($('#<%=txtTeamARate.ClientID %>').val() != "")) {
                        $("#teamA").removeClass("error");
                        var teamAL = parseInt($('#<%=txtTeamARate.ClientID %>').val());
                        over = $('#<%=txtTeamAOver.ClientID %>').val() == '' ? 0 : $('#<%=txtTeamAOver.ClientID %>').val();
                        teamId = $('#<%=hdnTeamAId.ClientID %>').val() == '' ? 0 : $('#<%=hdnTeamAId.ClientID %>').val();
                        lagadiRate = $('#<%=txtTeamARate.ClientID %>').val() == '' ? 0 : $('#<%=txtTeamARate.ClientID %>').val();


                    }
                    else {
                        //Display Validation for Entering Data.
                        $("#teamA").addClass("error");
                        return;
                    }
                }

                if (whichTeam == 'teamB') {
                    $("#btnTeamABettingStart").hide();
                    if (($('#<%=txtTeamBRate.ClientID %>').val() != "")) {
                        $("#teamB").removeClass("error");
                        var teamBL = parseInt($('#<%=txtTeamBRate.ClientID %>').val());
                        over = $('#<%=txtTeamBOver.ClientID %>').val() == '' ? 0 : $('#<%=txtTeamBOver.ClientID %>').val();
                        teamId = $('#<%=hdnTeamBId.ClientID %>').val() == '' ? 0 : $('#<%=hdnTeamBId.ClientID %>').val();
                        lagadiRate = $('#<%=txtTeamBRate.ClientID %>').val() == '' ? 0 : $('#<%=txtTeamBRate.ClientID %>').val();


                    }
                    else {
                        //Display Validation for Entering Data.
                        $("#teamB").addClass("error");
                        return;
                    }
                }
            }



            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                data: "{'bettingTypeId': " + bettingTypeId + ",'matchTypeId':" + matchTypeId + ", 'matchScheduleId':" + matchScheduleId + ",'teamId': " + teamId + ",'over':" + over + ",'lagadiRate': " + lagadiRate + "}",
                url: "AdminFancy.aspx/SaveBettingRecords",
                dataType: "json",
                success: function (data) {
                    if (data.d == 1) {
                        if (whichTeam == 'teamA') {
                            $("#btnTeamAEnd").show();
                            $("#btnTeamAStart").removeClass("btn hide");
                            $("#btnTeamAStart").addClass("btn red");
                            $("#btnTeamAStart").prop("disabled", true);
                            $('#btnTeamAEnd').focus();
                        }
                        if (whichTeam == 'teamB') {
                            $("#btnTeamBEnd").show();
                            $("#btnTeamBStart").removeClass("btn hide");
                            $("#btnTeamBStart").addClass("btn red");
                            $("#btnTeamBStart").prop("disabled", true);
                            $('#btnTeamBEnd').focus();
                        }

                    }
                },
                error: function (response) {
                    alert(response.responseText);
                }
            });
        }


        function UpdateBetting(whichTeam) {

            var bettingTypeId = $('#<%=drpBettingType.ClientID %>').val();
            if (whichTeam == 'teamA') {
                var lagadi = $('#<%=txtTeamARate.ClientID %>').val();

            }
            else if (whichTeam = 'teamB') {
                var lagadi = $('#<%=txtTeamBRate.ClientID %>').val();

            }
            if ($('#<%=drpBettingType.ClientID %> option:selected').text() == "Match") {

            }
            else {
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    data: "{'bettingTypeId':'" + bettingTypeId + "'}",
                    url: "AdminFancy.aspx/UpdateBettingRecords",
                    dataType: "json",
                    success: function (data) {
                        if (data.d == 1) {
                            if (whichTeam == 'teamA') {
                                $("#btnTeamAEnd").hide();
                                $("#btnTeamAStart").show();
                                $("#btnTeamABettingStart").hide();
                                $("#btnTeamBBettingStart").show();
                                $("#btnTeamAStart").removeClass("btn red");
                                $("#btnTeamAStart").addClass("btn");
                                $("#btnTeamAStart").prop("disabled", false);
                                $('#<%=txtTeamARate.ClientID %>').focus();
                                var teamAL = $('#<%=txtTeamARate.ClientID %>').val();
                                $('#<%=txtTeamARate.ClientID %>').attr("placeholder", teamAL);
                                $('#<%=txtTeamARate.ClientID %>').val('');

                            }
                            if (whichTeam == 'teamB') {
                                $("#btnTeamBEnd").hide();
                                $("#btnTeamBStart").show();
                                $("#btnTeamBBettingStart").hide();
                                $("#btnTeamABettingStart").show();
                                $("#btnTeamBStart").removeClass("btn red");
                                $("#btnTeamBStart").addClass("btn");
                                $("#btnTeamBStart").prop("disabled", false);
                                $('#<%=txtTeamBRate.ClientID %>').focus();
                                var teamBL = $('#<%=txtTeamBRate.ClientID %>').val();

                                $('#<%=txtTeamBRate.ClientID %>').attr("placeholder", teamBL);

                                $('#<%=txtTeamBRate.ClientID %>').val('');


                            }

                        }
                    },
                    error: function (response) {
                        alert('Error');
                    }
                });
            }
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
    <asp:HiddenField ID="hdnTeamAId" runat="server" />
    <asp:HiddenField ID="hdnTeamBId" runat="server" />
    <asp:HiddenField ID="hdnAdminId" runat="server" />
    <div class="container-fluid">
        <h3 class="page-title">
            Betting<small></small>
        </h3>
        <div class="alert alert-danger" id="layerError" runat="server" style="display: none;">
        </div>
        <div class="alert alert-success" id="layerSuccess" runat="server" style="display: none;">
        </div>
        <div id="divCommonRate" style="display: none;">
            Please <a href="MyProfile.aspx">click here</a> to change the rate.
        </div>
        <div class="row-fluid" id="bettingDiv">
            <div class="span12">
                <div class="portlet box blue">
                    <div class="portlet-title">
                        <div class="caption">
                            Betting</div>
                    </div>
                    <div class="portlet-body form">
                        <div class="form-horizontal form-view">
                            <div class="row-fluid">
                                <div class="span6">
                                    <div class="control-group">
                                        <label class="control-label">
                                            Match Type <span class="required">*</span></label>
                                        <div class="controls">
                                            <asp:DropDownList ID="drpMatchType" runat="server" OnSelectedIndexChanged="drpMatchType_SelectedIndexChanged"
                                                AutoPostBack="true">
                                            </asp:DropDownList>
                                            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Please enter match type"
                                                InitialValue="0" ValidationGroup="Betting" CssClass="required" ControlToValidate="drpMatchType"
                                                Display="Dynamic"></asp:RequiredFieldValidator>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row-fluid">
                                <div class="span6">
                                    <div class="control-group">
                                        <label class="control-label">
                                            Select Match<span class="required">*</span></label>
                                        <div class="controls">
                                            <asp:DropDownList ID="drpMatch" runat="server" OnSelectedIndexChanged="drpMatch_SelectedIndexChanged"
                                                AutoPostBack="true">
                                            </asp:DropDownList>
                                            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="Please enter match"
                                                InitialValue="0" ValidationGroup="Betting" CssClass="required" ControlToValidate="drpMatch"
                                                Display="Dynamic"></asp:RequiredFieldValidator>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row-fluid">
                                <div class="span6">
                                    <div class="control-group">
                                        <label class="control-label">
                                            Betting Type<span class="required">*</span></label>
                                        <div class="controls">
                                            <asp:DropDownList ID="drpBettingType" runat="server">
                                            </asp:DropDownList>
                                            <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="Please enter betting type"
                                                InitialValue="0" ValidationGroup="Betting" CssClass="required" ControlToValidate="drpBettingType"
                                                Display="Dynamic"></asp:RequiredFieldValidator>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row-fluid">
                                <div class="control-group" id="teamA">
                                    <label class="control-label">
                                        <asp:Label ID="lblTeamA" runat="server" CssClass="span6 m-wrap"> </asp:Label>
                                    </label>
                                    <div class="controls">
                                        <input id="btnTeamABettingStart" type="button" value="Start" class="btn hide" onclick="StartBettingTeamA()" />
                                        <asp:TextBox ID="txtTeamAOver" runat="server" placeholder="Over" CssClass="m-wrap span2 hide"></asp:TextBox>
                                        <asp:TextBox ID="txtTeamARate" runat="server" placeholder="Rate" CssClass="m-wrap span2 hide"></asp:TextBox>
                                        <input id="btnTeamAStart" type="button" value="BroadCast" class="btn hide" onclick="SaveBetting('teamA')" />
                                        <input id="btnTeamAEnd" type="button" value="End" class="btn hide" onclick="UpdateBetting('teamA')" />
                                    </div>
                                </div>
                            </div>
                            <div class="row-fluid">
                                <div class="control-group" id="teamB">
                                    <label class="control-label">
                                        <asp:Label ID="lblTeamB" runat="server" CssClass="span6 m-wrap"></asp:Label>
                                    </label>
                                    <div class="controls">
                                        <input id="btnTeamBBettingStart" type="button" value="Start" class="btn hide" onclick="StartBettingTeamB()" />
                                        <asp:TextBox ID="txtTeamBOver" runat="server" placeholder="Over" CssClass="m-wrap span2 hide"></asp:TextBox>
                                        <asp:TextBox ID="txtTeamBRate" runat="server" placeholder="Rate" CssClass="m-wrap span2 hide"></asp:TextBox>
                                        <input id="btnTeamBStart" type="button" value="BroadCast" class="btn hide" onclick="SaveBetting('teamB')" />
                                        <input id="btnTeamBEnd" type="button" value="End" class="btn hide" onclick="UpdateBetting('teamB')" />
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</asp:Content>
